#coding=utf-8
import urllib, urllib2, random, time
def print_red(s):
  print '\033[0;31;48m%s\033[0m'%s  
  
app_name = 'qq-email'
url = 'http://%s.appspot.com/receive_qq'%app_name

def is_online(num):
  while True:
    try:
      url = 'http://wpa.qq.com/pa?p=1:%s:1'%num
      f = urllib.urlopen(url)
      url2 = f.geturl()
      if url2.find('online') != -1:
        return True
      else: 
        return False
    except IOError, e:
      print e
      time.sleep(2)

def get_onlined_qq(a, b):
  while True:
    n = str(random.randint(a,b))
    print n
    r = is_online(n)
    if r:
      return n
    time.sleep(0.1)

while True:
  n = get_onlined_qq(50000000,500000000)
  print_red(n)
  
  values = {'qq':n}
  
  while True:
    try:
      data = urllib.urlencode(values)
      req = urllib2.Request(url, data)
      response = urllib2.urlopen(req)
      break
    except  IOError, e:
      print e
      time.sleep(5)
    

